package org.example;

public class Test1 {
    //leetcode 860 柠檬水找零 https://leetcode.cn/problems/lemonade-change/description/
    public boolean lemonadeChange(int[] bills) {
        int fiveCount = 0, tenCount = 0;
        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) fiveCount++;
            else if (bills[i] == 10) {
                fiveCount--;
                if (fiveCount < 0) return false;
                tenCount++;
            }else {
                if (fiveCount > 0 && tenCount > 0) {
                    fiveCount--;
                    tenCount--;
                }else if (fiveCount >= 3) {
                    fiveCount -= 3;
                }else {
                    return false;
                }
            }
        }
        return true;
    }
}
